-
-
Notifications
You must be signed in to change notification settings - Fork 11
TYP: Static typing support for numpy_quaddtype
#154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also have a CI step to verify these type stubs
|
||
# | ||
def is_longdouble_128() -> bool: ... | ||
def get_sleef_constant( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong - we need an override for the function since it returns normal integers for the integer constants bits and precision
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea of course; "bits"
and "precision"
return an int
. I'll fix this in a follow-up.
And out of curiosity, why is this a function instead of "bare" constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We wanted to keep all definitions in the C(++) code so that Python only re-exports them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constants can be re-exported 🤷🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean declaring the value a Python constant in the C++ code? That could be nice, though not something I'd know how to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea pretty much, but I'm not much of a C expert, so maybe I'm talking nonsense here. Although for the int
ones it shouldn't be too difficult I'm guessing?
@jorenham @SwayamInSync I left some comments that should be addressed in a follow-up |
Co-authored-by: Juniper Tyree <[email protected]>
I heard that
numpy_quaddtype
has been growing lately, so I figured that it might be nice to have some static typing support. So here it is.Mypy, stubtest, and pyright are all happy with it now (no errors are reported), even when they're run in strict mode.
To check for yourself, you can do something like
To run stubtest (validates correctness of stubs by inspecting the runtime, and also runs mypy to type-check the stubs):
$ stubtest --mypy-config-file pyproject.toml numpy_quaddtype Success: no issues found in 2 modules
To run type-check the stubs using pyright (in strict mode):
If you want to admire the juicy type coverage %:
$ pyright --ignoreexternal --verifytypes numpy_quaddtype # output omitted since that would spoil the fun ;)